<script type="text/javascript" src="./Public/avarat/js/jquery-1.7.1.min.js"></script>   
<script type="text/javascript" src="./Public/avarat/js/ajaxfileupload.js"></script>
<script type="text/javascript" src="./Public/avarat/js/artDialog4.1.6/jquery.artDialog.js?skin=default"></script>
<script type="text/javascript" src="./Public/avarat/js/artDialog4.1.6/plugins/iframeTools.js"></script>
<script type="text/javascript">
function clp(){
   return  $("#head_photo").click();
}
</script>

<div class="userinfo">

    <div class="wind_content1R" >
      <span class="wind_content1Rspan" >头像编辑</span>
      
      <ul class="wind_content1RULs1" style="margin-top:20px;">
      <span class="wind_myhead_son2" id="avatar_js" onClick="clp()" >上传头像</span>
       <input type="file" name="head_photo" id="head_photo" value="" style="display:none">  
        <input  type="hidden" name="photo_pic" id="photo_pic" value="">
<form method='post' id="myform2"  action="{:URL('User-Index/avatar')}" >
<!--头像显示-->
<div id="show_photo" style="wind_myhead_son2border:1px solid #f7f7f7;  height:100px; padding-top:20px; margin:auto;width: 95px;"><img id="head_photo_src" width="100" {if $vo.avatar}src="{$vo.avatar}"{else} src="./Public/avarat/images/default.gif" {/if}> </div>

<input type="hidden" name="avatar" id="avarat" value="{$vo.avatar}"/>
<div id="show_photo" style="wind_myhead_son2border:1px solid #f7f7f7;  height:100px; padding-top:20px; margin:auto;width: 95px;"><input type="submit" name="dosubmit" value="保存" class="wind_sub1"/></div>

</form>
      <div class="container">
            
        </div>
      </ul>
      
    </div>
    <div style="clear:both;margin-bottom:20px;"></div>
  </div>
</div>


<script>
$(document).ready(function(e){
		
	$('#head_photo').live('change',function(){ 
	//alert(22)
		ajaxFileUploadview('head_photo','photo_pic',"index.php?g=User&m=Upload&a=avarat");
	});	

});


function show_head(head_file){
	
	//插入数据库
	//$.post("{:U('Home/Index/update_head')}",{head_file:head_file},function(result){		
		$("#head_photo_src").attr('src',head_file);
		$("#avarat").val(head_file);		
	//});	

}

//文件上传带预览
function ajaxFileUploadview(imgid,hiddenid,url){
		
		
		$.ajaxFileUpload
		({
			url:url,
			secureuri:false,
			fileElementId:imgid,
			dataType: 'json',
			data:{name:'logan', id:'id'},
			success: function (data, status)
			{
				if(typeof(data.error) != 'undefined')
				{
					if(data.error != '')
					{
						var dialog = art.dialog({title:false,fixed: true,padding:0});
						dialog.time(2).content("<div class='tips'>"+data.error+"</div>");
					}else{

						var resp = data.msg;						
						if(resp != '0000'){
							var dialog = art.dialog({title:false,fixed: true,padding:0});
							dialog.time(2).content("<div class='tips'>"+data.error+"</div>");
							return false;
						}else{
							$('#'+hiddenid).val(data.imgurl);						

							art.dialog.open("index.php?g=User&m=Upload&a=avarat_img&img="+data.imgurl,{
								title: '裁剪头像',
								width:'580px',
								height:'400px'
							});						
							
							//dialog.time(3).content("<div class='msg-all-succeed'>上传成功！</div>");
						}
									

						
						
					}
				}
			},
			error: function (data, status, e)
			{
              //alert(e)
				dialog.time(3).content("<div class='tips'>"+e+"</div>");
			}
		})

		return false;
	}

</script>
